package canvas;

import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;

import objetos.CanvasGame;
import objetos.GamePanel;
import objetos.myCanvas;

public class CanvasGameComplet extends myCanvas{

	public static CanvasGameComplet instance = null;


	BufferedImage menuImage;

	long timerCompra, timerVenda;



	Random rnd = new Random();

	long timerCLick;

	public CanvasGameComplet() {

		menuImage = GamePanel.loadImage("./../win.jpg");
		//CanvasGame.instance.contagemRegressiva = 1;
		instance = this;		


	}


	@Override
	public void SimulaSe(long diftime) {
		timerCLick = diftime;
		//System.out.print("\n MAPA ATUAL DO SHOP => " + CanvasGame.MapaAtual+ "\n");
		if(CanvasGame.instance.liberaCarro2 == false){
			CanvasGame.instance.liberaCarro2 = true;
		}
		checaMouseLoja();

	}

	private void checaMouseLoja() {
		if(CanvasGame.instance.FIRE == true && timerCLick > 500){
			timerCLick = 0;
			CanvasGame.instance.heroi.X= 100; 
			CanvasGame.instance.heroi.Y= 300;

			CanvasGame.instance.FIRE = false;
			
			if (CanvasFases.instance == null) {
				CanvasFases fases = new CanvasFases();
			}
			GamePanel.canvasAtivo = CanvasFases.instance;

		}


	}

	public void DesenhaSe(Graphics2D dbg) {

		dbg.drawImage(menuImage, 0, 0, null); // tamanho da imagem

	}

	@Override
	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		int keyCode = e.getKeyCode();

		if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_SPACE) {
			if (CanvasFases.instance == null) {
				CanvasFases fases = new CanvasFases();
			}
			GamePanel.canvasAtivo = CanvasFases.instance;
		}

	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseMoved(MouseEvent e) {
		//System.out.print("MOVEU O MOUSEEEEEEEEEEEEE ");
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}


	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		//System.out.print("Clicou AEEEEEEEEEEEEEEH ");
		CanvasGame.instance.MouseX = e.getX();
		CanvasGame.instance.MouseY = e.getY();
		int cont = 0;

	}

	public static BufferedImage loadImage(String source) {
		BufferedImage image = null;
		try {
			BufferedImage tmp = ImageIO.read(CanvasGame.instance.getClass()
					.getResource(source));
			image = new BufferedImage(tmp.getWidth(), tmp.getHeight(),
					BufferedImage.TYPE_INT_ARGB);
			image.getGraphics().drawImage(tmp, 0, 0, null);
			tmp = null;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return image;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		System.out.print("CLICOU NO MOUSE AEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEH");

	}



}
